<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.gzsz.util.DBUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String patient_name = request.getParameter("patient_name");
    String patient_gender = request.getParameter("patient_gender");
    String patient_age = request.getParameter("patient_age");
    String admission_date = request.getParameter("admission_date");
    String discharge_date = request.getParameter("discharge_date");
    String diagnosis = request.getParameter("diagnosis");
    String treatment = request.getParameter("treatment");
    String attending_doctor = request.getParameter("attending_doctor");
    String remarks = request.getParameter("remarks");

    // 空值检查
//    if (Name == null ||Password == null || Role == null) {
//        out.println("参数不能为空，请检查表单数据。");
//    } else {
    try {
        DBUtil dbUtil = new DBUtil();
        // 构造带参数的 SQL 语句
        String sql = "INSERT INTO bingli (patient_name, patient_gender, patient_age, admission_date, discharge_date, diagnosis, treatment, attending_doctor, remarks)" +
                " VALUES ('" + patient_name + "', '" + patient_gender + "', '" + patient_age + "', '" + admission_date + "', '"+ discharge_date + "', '" + diagnosis + "', '" + treatment + "', '" + attending_doctor + "', '" + remarks + "');";
        // 3. 创建预编译命令对象
//            String sql = "INSERT INTO users (name, gender, age, phone, user_account) VALUES (?, ?, ?, ?, ?)";
//            preparedStatement = connection.prepareStatement(sql);
//
//// 设置参数
//            preparedStatement.setString(1, name);
//            preparedStatement.setString(2, gender);
//            preparedStatement.setInt(3, Integer.parseInt(age));
//            preparedStatement.setString(4, phone);
//            preparedStatement.setString(5, number);
        // 执行插入操作
        int i = dbUtil.executeUpdateBySQL(sql);
        if (i > 0) {
            response.sendRedirect("BingLi.jsp");
        } else {
            out.println("插入失败");
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.println("发生错误：" + e.getMessage());
//        }
    }
%>